package com.sf.business.audit.controller;

import com.sf.business.audit.domain.BusCarPackageInfo;
import com.sf.business.audit.qo.BusCarPackageHistoryInfo;
import com.sf.business.audit.service.IBusCarPackageInfoService;
import com.sf.business.audit.vo.BusCarPackageAuditResultVO;
import com.sf.common.annotation.Log;
import com.sf.common.core.controller.BaseController;
import com.sf.common.core.domain.AjaxResult;
import com.sf.common.core.page.TableDataInfo;
import com.sf.common.enums.BusinessType;
import com.sf.common.utils.poi.ExcelUtil;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 套餐信息Controller
 * 
 * @author lh
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/business/audit/carPackageInfo")
public class BusCarPackageInfoController extends BaseController
{
    @Autowired
    private IBusCarPackageInfoService busCarPackageInfoService;

    /**
     * 查询套餐信息列表
     */
    @PreAuthorize("@ss.hasPermi('business/audit:carPackageInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusCarPackageInfo busCarPackageInfo)
    {
        startPage();
        List<BusCarPackageInfo> list = busCarPackageInfoService.selectBusCarPackageInfoList(busCarPackageInfo);
        return getDataTable(list);
    }

    /**
     * 导出套餐信息列表
     */
    @PreAuthorize("@ss.hasPermi('business/audit:carPackageInfo:export')")
    @Log(title = "套餐信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusCarPackageInfo busCarPackageInfo)
    {
        List<BusCarPackageInfo> list = busCarPackageInfoService.selectBusCarPackageInfoList(busCarPackageInfo);
        ExcelUtil<BusCarPackageInfo> util = new ExcelUtil<BusCarPackageInfo>(BusCarPackageInfo.class);
        util.exportExcel(response, list, "套餐信息数据");
    }

    /**
     * 获取套餐信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business/audit:carPackageInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busCarPackageInfoService.selectBusCarPackageInfoById(id));
    }

    /**
     * 新增套餐信息
     */
    @PreAuthorize("@ss.hasPermi('business/audit:carPackageInfo:add')")
    @Log(title = "套餐信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCarPackageInfo busCarPackageInfo)
    {
        return toAjax(busCarPackageInfoService.insertBusCarPackageInfo(busCarPackageInfo));
    }

    /**
     * 修改套餐信息
     */
    @PreAuthorize("@ss.hasPermi('business/audit:carPackageInfo:edit')")
    @Log(title = "套餐信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCarPackageInfo busCarPackageInfo)
    {
        return toAjax(busCarPackageInfoService.updateBusCarPackageInfo(busCarPackageInfo));
    }

    /**
     * 删除套餐信息
     */
    @PreAuthorize("@ss.hasPermi('business/audit:carPackageInfo:remove')")
    @Log(title = "套餐信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busCarPackageInfoService.deleteBusCarPackageInfoByIds(ids));
    }

    /**
     * 审核流程查看
     * @param id    bus_car_package_audit 表的 id
     * @return      审核流程进度图
     */
    @GetMapping("/process/{id}")
    public void queryProcess(@PathVariable Long id, HttpServletResponse response) throws IOException {
        InputStream inputStream = busCarPackageInfoService.queryProcess(id);
        IOUtils.copy(inputStream, response.getOutputStream());
    }

    /**
     * 取消审核
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable Long id) {
        busCarPackageInfoService.cancel(id);
        return AjaxResult.success();
    }

    /**
     * 我的 待办
     * @return
     */
    @GetMapping("/todo")
    public TableDataInfo todo() {
    	List<BusCarPackageInfo> list = busCarPackageInfoService.todo();
    	return getDataTable(list);
    }

    /**
     * 我的 已办
     * @return
     */
    @GetMapping("/done")
    public TableDataInfo done() {
    	List<BusCarPackageInfo> list = busCarPackageInfoService.done();
    	return getDataTable(list);
    }

    /**
     * 审核 (通过 / 拒绝)
     * @return
     */
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody BusCarPackageAuditResultVO vo) {
        busCarPackageInfoService.audit(vo);
        return AjaxResult.success();
    }


    /**
     * 审批历史查看
     * @param id
     * @throws IOException
     */
    @GetMapping("/history/{id}")
    public TableDataInfo history(@PathVariable String id) throws IOException {
        List<BusCarPackageHistoryInfo> list = busCarPackageInfoService.selectHistoryInfoById(id);
        return getDataTable(list);
    }
}
